<?php

class ctrl_wish_wishBalance extends L {

    /**
     * 描述 ：Wish账单明细页面展示
     * 作者 ：Zoro.Zhu
    **/
    public function index(){
        $this->view->_pagingHtml = $this->paging();;
        $this->view->accountList = model_com::getAccount('wish');
        $this->view->type = model_com::getVsConfig('wishBalanceType');
        $this->view->headTitle = 'Wish账单明细';
        $this->display('/html/wish/wishBalance.html');
    }

    /**
     * 描述 : 获取分页
     * 作者 : Zoro.Zhu
     */
    public function &paging($params = array()){
        $sql = model_wishBalance::searchSql($params);
        $config = array( 
            '账号' => array(
                '_attr' => array(
                    'body' => '{`account`}',
                    'sort' => 'account'
                )
            ),
            '时间' => array(
                '_attr' => array(
                    'body' => '{`date`}',
                    'sort' => 'date'
                )
            ),
            '数据类型' => array(
                '_attr' => array(
                    'body' => '{`type`}',
                    'sort' => 'type'
                )
            ),
            '金额（RMB）' => '{`amount`}',
            '凭据单号' => '{`orderId`}',
            '_attr' => array(
                "attr" => array (
                    "table" => 'id=wishBalanceList class="table table-hover table-condensed table-striped table-scroll jsHoverDetails textC"',
                    "btr" => "align='center' class='of-paging_item_odd tr_{`id`}'",
                ),
                'data' => &$sql,
                'params' => &$params,
                'call' => array($this, 'asCall'),
                'method' => __METHOD__,
                'save' => 'auto',
                'empty' => '查无此数据'
            )
        );
        return $this->_com->paging($config);
    }

    /**
     * 描述 : 整理数据
     * 作者 : Zoro.Zhu
     */
    public function asCall(&$data){
        $type = model_com::getVsConfig('wishBalanceType');
        foreach($data['data'] as &$val){
            $info = json_decode($val['data'], true);
            $val['type'] = !empty($type[$val['type']]) ? $type[$val['type']] : $val['type'];
            $val['amount'] = round($info['amount'], 2);
            $val['orderId'] = $info['order_id'] != 'None' ? $info['order_id'] : '';
            empty($val['orderId']) && $val['orderId'] = $info['merchant_payment_id'] != 'None' ? $info['merchant_payment_id'] : '';
            empty($val['orderId']) && $val['orderId'] = $info['campaign_id'] != null ? $info['campaign_id'] : '';
            empty($val['orderId']) && $val['orderId'] = $info['warning_id'] != null ? $info['warning_id'] : '';
            empty($val['orderId']) && $val['orderId'] = $info['fine_id'] != null ? $info['fine_id'] : '';
        }
    }

}
return true;